const mongoose = require('mongoose');
const db = mongoose.connect("mongodb://localhost:27017/test", { useNewUrlParser: true }, function (err) {
    if (err) {
        console.log(err);
    } else {
        console.log("Connection success !")
    }
})

const Schema = mongoose.Schema;

//用户
let carSchema = new Schema({
    car_id: { type: String },
    car_name: { type: String },
    create_time: {
        type: String,
        default: Date.now
    }
})

let lunboSchema = new Schema({
    url: { type: String },
    img: { type: String }
})

let newslistSchema = new Schema({
    id: { type: String },
    title: { type: String },
    add_time: {
        type: String,
        default: Date.now
    },
    zhaiyao: { type: String },
    click: { type: Number },
    img_url: { type: String }
})

let newsinfoSchema = new Schema({
    id: { type: String },
    title: { type: String },
    add_time: { 
        type: String,
        default: Date.now
    },
    click: { type: Number },
    content: { type: String }
})

let commentSchema = new Schema({
    uid: { 
        type: String,
        default: '20' 
    },
    user_name: { 
        type: String,
        default: '匿名用户'
     },
    add_time: { 
        type: String,
        default: Date.now 
    },
    content: { type: String },
    cid: { type: String }
})

let imgcategorySchema = new Schema({
    title: { type: String },
    id: { type: Number }
})

let imglistSchema = new Schema({
    id: { type: Number },
    title: { type: String },
    img_url: { type: String },
    zhaiyao: { type: String }
})

let imginfoSchema = new Schema({
    id: { type: Number },
    title: { type: String },
    click: { type: Number },
    img_url: { type: String },
    add_time: {
        type: String,
        default: Date.now()
    },
    content: { type: String }
})

let imgthumSchema = new Schema({
    src : { type: String }
})

let goodslistSchema = new Schema({
    id: { type: String },
    title: { type: String },
    add_time: {
        type: String,
        default: Date.now()
    },
    zhaiyao: { type: String },
    click: { type: Number },
    img_url: { type: String },
    sell_price: { type: Number },
    market_price: { type: Number },
    stock_quantity: { type: Number }
})

let goodsinfoSchema = new Schema({
    id: { type: String },
    title: { type: String },
    add_time: {
        type: String,
        default: Date.now()
    },
    goods_no: { type: String },
    stock_quantity: { type: Number },
    market_price: { type: Number },
    sell_price: { type: Number }
})

let goodsdescSchema = new Schema({
    title: { type: String },
    content: { type: String }
})

let shopcarlistSchema = new Schema({
    cou: { type: Number },
    id: { type: String },
    title: { type: String },
    sell_price: { type: Number },
    thumb_path: { type: String }
})

exports.Lunbo = mongoose.model('Lunbo', lunboSchema)
exports.Car = mongoose.model('Car', carSchema)
exports.Newslist = mongoose.model('Newslist', newslistSchema)
exports.Newsinfo = mongoose.model('Newsinfo', newsinfoSchema)
exports.Comment = mongoose.model('Comment', commentSchema)
exports.Imgcategory = mongoose.model('Imgcategory',imgcategorySchema)
exports.Imglist = mongoose.model('Imglist',imglistSchema)
exports.Imginfo = mongoose.model('Imginfo',imginfoSchema)
exports.Imgthum = mongoose.model('Imgthum',imgthumSchema)
exports.Goodslist = mongoose.model('Goodslist',goodslistSchema)
exports.Goodsinfo = mongoose.model('Goodsinfo',goodsinfoSchema)
exports.Goodsdesc = mongoose.model('Goodsdesc',goodsdescSchema)
exports.Shopcarlist = mongoose.model('Shopcarlist',shopcarlistSchema)